{template '_header'}

<div class="page-header">当前位置：
    <span class="text-primary">
        {if !empty($opid)}【{$operator['province']}{if $operator['type'==2]}{$operator['city']}{$operator['dist']}{/if}】区域的{/if}
        {if !empty($channelid)}【{$channel['realname']}】行业服务商的{/if}
        {if !empty($manageid)}【{$manage['realname']}】店主的{/if}
        门店管理
    </span>
</div>

<div class="page-content">
<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
    <input type="hidden" name="c" value="site" />
    <input type="hidden" name="a" value="entry" />
    <input type="hidden" name="m" value="mx_shop" />
    <input type="hidden" name="do" value="web" />
    <input type="hidden" name="r" value="mendian" />
    <input type="hidden" name="opid" value="{$opid}" />
    <input type="hidden" name="chid" value="{$channelid}" />
    <input type="hidden" name="maid" value="{$manageid}" />

    <div class="page-toolbar">
        <div class="col-sm-4">
            <div class="input-group-btn">
                <div class="pull-left">
                    {ifp 'platform.add'}
                    <a class="btn btn-primary btn-sm" href="{php echo webUrl('mendian/post')}"><i class="fa fa-plus"></i> 添加门店</a>
                    {/if}
                </div>
                <button class="btn btn-default btn-sm"  type="button" data-toggle='refresh'><i class='fa fa-refresh'></i></button>
                {ifp 'mendian.delete'}
                <button class="btn btn-default btn-sm" type="button" data-toggle='batch-remove' data-confirm="确认要删除?" data-href="{php echo webUrl('mendian/mddel')}"><i class='fa fa-trash'></i> 删除</button>
                {/if}
            </div>
        </div>

        <div class="col-sm-8 pull-right">

            <div class="input-group">
                <div class="input-group-select">
                    <div class="col-xs-3 col-sm-2 col-lg-2">
                        <select name="selprov" class="form-control input-sm select-md" id="selprov" onchange="loadcity();">
                            <option value="0">请选择省</option>
                            {loop $province $row}
                            <option value="{$row['province']}" {if $row['province']==$_GPC['selprov']}selected="selected"{/if}>{$row['province']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="input-group-select">
                    <div class="col-xs-3 col-sm-2 col-lg-2">
                        <select name="selcity" class="form-control input-sm select-md" id="selcity" onchange="loaddist();">
                            <option value="0">请选择市</option>
                            {loop $city $row}
                            <option value="{$row['city']}" {if $row['city']==$_GPC['selcity']}selected="selected"{/if}>{$row['city']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="input-group-select">
                    <div class="col-xs-3 col-sm-2 col-lg-2">
                        <select name="seldist" class="form-control input-sm select-md" id="seldist">
                            <option value="0">请选择区</option>
                            {loop $dist $row}
                            <option value="{$row['dist']}" {if $row['dist']==$_GPC['seldist']}selected="selected"{/if}>{$row['dist']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="input-group-select">
                    <select name='mdcate_id' class='form-control  input-sm select-md' style="width:140px;"  >
                        <option value='0'>门店分类</option>
                        {loop $md_fenlei $row}
                        <option value="{$row['id']}" {if $row['id']==$_GPC['mdcate_id']}selected{/if}>{$row['name']}</option>
                        {/loop}
                    </select>
                </div>
                <div class="input-group-select">
                    <select name='status' class='form-control  input-sm select-md' style="width:100px;"  >
                        <option value="0" {if empty($status)} selected  {/if}>状态</option>
                        <option value="1" {if $status==1} selected  {/if}>显示</option>
                        <option value="2" {if $status==2} selected  {/if} >不显示</option>
                    </select>
                </div>
                <input type="text" class="form-control input-sm"  name="keyword" value="{$_GPC['keyword']}" placeholder="门店关键字" />
                <span class="input-group-btn">
                    <button class="btn btn-sm btn-primary" type="submit"> 搜索</button>
                </span>
            </div>
        </div>
    </div>
</form>
{if count($list)>0}

<table class="table table-hover table-responsive">
    <thead class="navbar-inner" >
    <tr>
        <th style="width:25px;"><input type='checkbox' /></th>
        <th style='width:50px;'>id</th>
        <th style='width:200px;'>门店名称</th>
        <th style='width:160px;'>所属区域</th>
        <th style='width:85px;'>店主头像</th>
        <th style='width:85px;'>服务商头像</th>
        <th style='width:80px;'>状态</th>
        <th style='width:150px;'>操作</th>
    </tr>
    </thead>
    <tbody>
    {loop $list $row}
    <tr>
        <td><input type='checkbox'   value="{$row['id']}"/></td>
        <td ><span>{$row['id']}</span></td>
        <td ><span>{$row['mendianname']}</span></td>
        <td ><span>{$row['province']}{if !empty($row['city'])}-{$row['city']}{/if}</span></td>
        <td ><img src="{$row['manageavatar']}" style="width:70px;" alt="{$row['managename']}" title="{$row['managename']}"></td>
        <td ><img src="{$row['channelavatar']}" style="width:70px;" alt="{$row['channelname']}" title="{$row['channelname']}"></td>
        <td>
            <span class='label {if $row['status']==1}label-success{else}label-default{/if}'
            {ifp 'mendian.status'}
            data-toggle='ajaxSwitch'
            data-switch-value='{$row['status']}'
            data-switch-value0='0|不显示|label label-default|{php echo webUrl('mendian/status',array('status'=>1,'id'=>$row['id']))}'
            data-switch-value1='1|显示|label label-success|{php echo webUrl('mendian/status',array('status'=>0,'id'=>$row['id']))}'
            {/if}
            >
            {if $row['status']==1}显示{else}不显示{/if}</span>
        </td>
        <td  style="overflow:visible;">
            {ifp 'mendian.edit'}
            <div class="btn-group btn-group-sm">
                {if empty($opid)}
                    <a class="btn btn-default dropdown-toggle" href="{php echo webUrl('mendian/post', array('id'=>$row['id'], 'opid'=>$opid, 'chid'=>$channelid, 'maid'=>$manageid))}"><i class="fa fa-edit"></i>编辑</a>
                {else}
                    <a class="btn btn-default dropdown-toggle" href="{php echo webUrl('mendian/post', array('id'=>$row['id'], 'opid'=>$opid))}"><i class="fa fa-edit"></i>编辑</a>
                {/if}

                {ifp 'mendian.delete'}
                <a data-toggle='ajaxRemove' href="{php echo webUrl('mendian/mddel', array('id'=>$row['id']))}" class="btn btn-default btn-sm" data-confirm="确认要删除门店吗?"><i class="fa fa-trash"></i> 删除</a>
                {/if}
            </div>
            {/if}
        </td>
    </tr>
    {/loop}
    </tbody>
</table>
{$pager}

    {else}
    <div class="panel panel-default">
        <div class="panel-body empty-data">未查询到相关数据</div>
    </div>
    {/if}
</div>

<script language="javascript">

    require(['bootstrap'],function(){
        $("[rel=pop]").popover({
            trigger:'manual',
            placement : 'left',
            title : $(this).data('title'),
            html: 'true',
            content : $(this).data('content'),
            animation: false
        }).on("mouseenter", function () {
            var _this = this;
            $(this).popover("show");
            $(this).siblings(".popover").on("mouseleave", function () {
                $(_this).popover('hide');
            });
        }).on("mouseleave", function () {
            var _this = this;
            setTimeout(function () {
                if (!$(".popover:hover").length) {
                    $(_this).popover("hide")
                }
            }, 100);
        });
    });

    function loadcity() {

        $("#selcity").html( '<option value="0">请选择市</option>');
        $("#seldist").html( '<option value="0">请选择区</option>');
        var str = $("#selprov").val();
        if(str!=0) {
            $.post("{php echo webUrl('mendian/mdajax',array('foo'=>'city'));}", {str: str}, function (data) {
                if (data.status == 1) {
                    var json = data.data;
                    var _html = '<option value="0">请选择市</option>';
                    for (var o in json) {
                        if (json[o].city != '') {
                            _html += '<option value="' + json[o].city + '" >' + json[o].city + '</option>';
                        }
                    }
                    $("#selcity").html(_html);
                }

            }, 'json')
        }
    }

    function loaddist(){


        $("#seldist").html( '<option value="0">请选择区</option>');
        var selcity = '#selcity';
        var str=$(selcity).val();
        if(str != 0) {

            $.post("{php echo webUrl('mendian/mdajax',array('foo'=>'dist'));}", {str: str}, function (data) {
                if (data.status == 1) {
                    var json = data.data;
                    var _html = '<option value="0">请选择区</option>';
                    for (var o in json) {
                        if(json[o].dist != ''){
                            _html += '<option value="' + json[o].dist + '" >' + json[o].dist + '</option>';
                        }
                    }
                    $('#seldist').html(_html);
                }

            }, 'json')
        }
    }

</script>

{template '_footer'}